package com.gz.thread.runnable;

public class BuyTricks implements Runnable {

    int trickNum = 10;//线程并发问题，会导致数据错乱。线程不安全

    public void run() {
        while (true) {
            if (trickNum <= 0) {
                break;
            }
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "----->  buy " + trickNum--);
        }
    }


    public static void main(String[] args) {
        BuyTricks buyTricks = new BuyTricks();

        new Thread(buyTricks,"aaa").start();
        new Thread(buyTricks,"bbb").start();
        new Thread(buyTricks,"ccc").start();
    }
}
